package cn.it.service.impl;

import cn.it.anno.MyAutowired;
import cn.it.anno.MyService;
import cn.it.anno.MyTransactional;
import cn.it.dao.AccountDao;
import cn.it.pojo.Account;
import cn.it.service.TransferService;

import java.sql.SQLException;

@MyService("TransferService")
@MyTransactional
public class TransferServiceImpl implements TransferService {

    @MyAutowired
    private AccountDao accountDao ;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }


    public void transfer(String fromCardNo, String toCardNo, Double money) throws SQLException {

        Account from = accountDao.findById(fromCardNo);
        Account to = accountDao.findById(toCardNo);

        from.setMoney(from.getMoney()-100);
        to.setMoney(to.getMoney()+100);

        accountDao.update(from);
        //int a=1/0;
        accountDao.update(to);

    }
}
